#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>
int main()
{
    extern char** environ;
    // putenv("MY_ENV=6666666666666");
    pid_t id=fork();
    if(id==0)
    {
        //char *const myargv[]={
        //    "ls",
        //    "-a",
        //    "-l",
        //    NULL
        //};
        printf("before,I am a process,pid:%d,ppid:%d\n",getpid(),getppid());
        //这类方法的标准写法 
        //execl("/usr/bin/ls","ls","-a","-l",NULL);//必须以NULL结尾
        //execv("/usr/bin/ls",myargv);
        //execvp("ls",myargv);
        //execlp("/usr/bin/ls","ls","-a","-l",NULL);
        //execlp("ls","ls","-a","-l",NULL);
        //execl("/usr/bin/top","top",NULL);//必须以NULL结尾
        //execl("./otherexe","otherexe",NULL);
        //execl("/usr/bin/bash","bash","test.sh",NULL);
        //execl("/usr/bin/python3","python3","test.py",NULL);
        char*const myargv[]={
            "otherexe",
            "-a",
            "-b",
            "-c",
            NULL
        };
        char *const myenv[]={
            "MYVAL=123666",
            "MYlll=567999",
            NULL
        };
        // execv("./otherexe",myargv);
        //execle("./otherexe","otherexe","-a","-w",NULL,environ);
        execle("./otherexe","otherexe","-a","-w",NULL,myenv);
        printf("After,I am a process,pid:%d,ppid:%d\n",getpid(),getppid());
        exit(0);
    }
    pid_t ret=waitpid(id,NULL,0);
    if(ret>0)
    {
        printf("wait successfully,father pid:%d,ret:%d\n",getpid(),ret);
    }
    return 0;
}
